# -*- coding: utf-8 -*-
"""
@Time    : 2024/7/17 13:57 
@Author  : ZhangShenao 
@File    : draw_trend_curve.py 
@Desc    : 绘制市场行情曲线
"""
import pandas as pd
import requests

# 获取行情数据的时间段
periods = '3600'

# 通过Http请求btc历史价格数据
data = requests.get('https://api.cryptowat.ch/markets/gemini/btcusd/ohlc', params={
    'periods': periods,
}).json()

print(data)

# 将响应的json数据转换成Pandas DataFrame
# 转换成pandas的data frame
df = pd.DataFrame(
    data["result"][periods],
    columns=[
        "收盘时间",
        "开盘时间",
        "最高价",
        "最低价",
        "收盘价",
        "成交量",
        "NA"
    ]
)

# 输出
print(df.head())
ax = df["收盘价"].plot(figsize=(14, 7))
fig = ax.get_figure()
fig.savefig("closeprice.png")
